<!DOCTYPE html>
<html lang="en">

	<head>
		<meta charset="UTF-8">
		<meta name="viewport" content="width=device-width, initial-scale=1.0">
		<meta http-equiv="X-UA-Compatible" content="ie=edge">
		<title>Document</title>
		<script src="https://cdn.jsdelivr.net/npm/vue@2.5.17/dist/vue.js"></script>
		<script src="https://cdn.bootcss.com/jquery/3.3.1/jquery.js"></script>
		<script src="https://test.xiaogj.com/js/libs/avalon.js"></script>
	</head>

	<body>
		<div id="app">
			首页
		</div>
		<div ms-controller="test" ms-click="click">
			扉页
		</div>
	</body>
	<script>
		(function() {
			function sendErr(news) {
				news = JSON.stringify(news);
				news = 'payload=' + news;
				var xhr = new XMLHttpRequest();
				xhr.responseType = "JSON";
				xhr.open('POST', 'https://hook.bearychat.com/=bwEne/incoming/50fe6592e6e0bc6396afaf5ebd52792e', true); // 上报给node中间层处理
				xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded"); // 设置请求头
				xhr.send(news);
			};

			window.onerror = function(errorMessage, scriptURI, lineNo, columnNo, userAgent, error) {
				// 构建错误对象
				var errorObj = {
					errorMessage: errorMessage || null, // 异常信息
					scriptURI: scriptURI || null, // 异常文件路径
					lineNo: lineNo || null, // 异常行号
					columnNo: columnNo || null, // 异常列号
					stack: error && error.stack ? error.stack : null // 异常堆栈信息
				};
				// "** 异常信息: **"+errorObj.errorMessage+"。"+"异常行号-"+errorObj.lineNo+"。异常列号-"+errorObj.columnNo+"。异常堆栈信息："+errorObj.stack
				// http://test.xiaogj.com/js/libs/nanoscroller/jquery.nanoscroller.min.js.map
				console.log(errorObj);
				var lncomingPar = {
					"text": "错误提醒！", //标题
					"markdown": true,
					//"channel":"",//讨论组名字
					//"user": "Chendye", //用户名
					"attachments": [{
						"title": window.navigator.userAgent,
						"text": "{** errorMessage : **" + errorObj.errorMessage + "," +
							" ** scriptURI : **" + errorObj.scriptURI + "," +
							" ** lineNo : **" + errorObj.lineNo + "," +
							"** columnNo : **" + errorObj.columnNo + "," +
							"** stack : **" + errorObj.stack +
							"}",
						"color": "#ff111f",
					}]
				};
				sendErr(lncomingPar);
			};
			window.errorCatch = function(framework) {
				Vue.config.errorHandler = function(err, vm, info) {
					let {
						message,
						name,
						script,
						line,
						column,
						stack
					} = err;
					let lncomingPar = {
						"text": "vue异常报告！", //标题
						"markdown": true,
						//"channel":"",//讨论组名字
						//"user": "3033244122@qq.com", //用户名
						"attachments": [{
							"title": "异常类型:" + name,
							"text": stack + " ** userAgent : **" + window.navigator.userAgent,
							"color": "#ff111f",
						}]
					};
					sendErr(lncomingPar);
				}

			}
		})()
	</script>
	<script>
		//avalon异常捕获，
		var vm = avalon.define({
			$id: "test",
			w: 100,
			h: 100,
			click: function() {
				vm.w = parseFloat(vm.w) + 10;
				vm.h = parseFloat(vm.h) + 10;
				console.log(a);
			}
		})

		// 模拟异常
		new Vue({
			el: '#app',
			mounted: function() {
				console.log(a);
			},
		})
		a = b;
		console.log(vm)
		// 错误1
		// console.log(a);
	</script>
	<!--<script src="dist/a.js"></script>-->
	<!--<script>doSomething()</script>-->

</html>